package com.lczyfz.campusinfo.modules.campusinfoexam.web;

import com.lczyfz.campusinfo.common.persistence.Page;
import com.lczyfz.campusinfo.common.utils.ApiResultUtils;
import com.lczyfz.campusinfo.common.web.BaseController;
import com.lczyfz.campusinfo.modules.campusinfoexam.entity.CampusinfoExam;
import com.lczyfz.campusinfo.modules.campusinfoexam.service.CampusinfoExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * Created by yt on 2017/10/24.
 * 模拟考试管理 api 接口
 */
@Controller
@RequestMapping(value = "${frontPath}/campusinfoexam/campusinfoExam")
public class CampusinfoExamApiController extends BaseController {

    @Autowired
    private CampusinfoExamService campusinfoExamService;

    /**
     * 模拟考试信息管理
     */
    @RequestMapping(value = "examList")
    @ResponseBody
    public Map<String, Object> getExamList(CampusinfoExam campusinfoExam, HttpServletRequest request, HttpServletResponse response) {
        Page<CampusinfoExam> page = campusinfoExamService.findPage(new Page<CampusinfoExam>(request, response), campusinfoExam);
        Map<String, Object> map = ApiResultUtils.getBaseMapSuccess();
        map.put("page", page.getList());
        map.put("pageNo", page.getPageNo());
        map.put("count", page.getCount());
        map.put("totalPage", page.getTotalPage());
        return map;
    }

    /**
     * 添加模拟考试信息
     */
    @RequestMapping(value = "addExam")
    @ResponseBody
    public Map<String, Object> addExam(CampusinfoExam campusinfoExam) {
        Map<String, Object> map = ApiResultUtils.getBaseMapSuccess();
        if (campusinfoExam != null) {
            campusinfoExamService.save(campusinfoExam);
            map.put("message", "保存模拟考试信息成功");
        } else {
            map.put("message", "保存模拟考试信息失败");
        }
        return map;
    }
}
